package com.tenbent.product.base.spring.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * 判断 placeholderConfigurer 是否已经注册到spring context 上线文
 *
 * Created by ThinkPad on 2017/8/15.
 */
public class PropertySourcesPlaceholderExitsCondition implements Condition {

	@Override
	public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
		try {
			PropertySourcesPlaceholderConfigurer placeholderConfigurer = conditionContext.getBeanFactory()
					.getBean(PropertySourcesPlaceholderConfigurer.class);
			return true;// placeholderConfigurer != null ? true : false;
		} catch (Exception e) {
			// e.printStackTrace();
		}
		return true;
	}
}
